<template>
	<view class="container">
		<uniNavBar :name="info.title" nextFlag="true" rightText="flase" bac="redbac"></uniNavBar>
		<view class="header-image" v-if="type==3">
			<video class="video" :src="info.video" controls></video>
		</view>
		<view class="imgList" v-if="type==1">
			<image v-for="(item,idx) in info.images" :key="idx" :src="item" mode=""></image>
		</view>
		<view class="tab-box">
			<view :class="index == 0 ? 'after' : ''" @click="tap(0)">作品介绍</view>
			<view :class="index == 1 ? 'after' : ''" @click="tap(1)">打赏记录</view>
		</view>
		<view class="content" v-if="index == 1">
			<view class="comont-records" v-for="item in reward" :key="item.id">
				<image :src="item.user.avatar"></image>
				<view class="navor-records-content">
					<view class="">
						<view class="records-name">{{item.user.nickname}}</view>
						<view class="records-date">{{item.time}}</view>
					</view>
					<view class="floews">赠送{{item.ticket}}朵鲜花</view>
					<view class="addnumber">+{{item.ticket}}</view>
				</view>
			</view>
			<view class="null" v-if="!reward.length">
				<text>还没有票数，快去支持！！！</text>
			</view>
			
		</view>

		<view class="content" v-if="index == 0">
			<view class="">
				<view class="author-commonts">
					<image class="author-img" :src="userInfo.avatar"></image>
					<view class="author-content">
						<view class="author-name">{{userInfo.nickname}}</view>
						<view class="author-details">{{info.content}}</view>
						<!-- <view class="author-flex">
							<view>学校：沈阳市第一学校</view>
							<view>班级：一年级</view>
						</view> -->
						<view class="author-flex flex-ens">
							<view>
								<image src="../../static/look.png"></image>
								<text>{{info.browse}}</text>
							</view>
							<view @tap="sendValueState=true">
								<image src="../../static/pinglun.png"></image>
								<text>{{commentList.length}}</text>
							</view>
							<view @tap="tickets">
								<image src="../../static/floewsA.png"></image>
								<text>{{info.ticket}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="null" v-if="!commentList.length">
					<text>还没有评论，快来抢沙发！！！</text>
				</view>
				<view class="comont-list" v-for="item in commentList" :key="item.id">
					<view class="navor-list-image">
						<image :src="item.user.avatar"></image>
						<view class="navor-list-content">
							<view class="">{{item.user.nickname}}</view>
							<view class="">{{item.create_time}}</view>
						</view>
					</view>
					<view class="navor-content">{{item.content}}</view>
					<view class="img-flex">
						<!-- <view>
							<image src="../../static/pinglun.png"></image>
							<text>评论</text>
						</view> -->
						<!-- <view>
							<image src="../../static/zan.png"></image>
							<text>点赞</text>
						</view> -->
					</view>
				</view>
			
			</view>
			<view class="sendComment" v-if="sendValueState">
				<input class="uni-input" v-model="comment" focus placeholder="请输入评论内容..." />
				<text :class="comment?'sendBtn act':'sendBtn'" @tap="send">发送</text>
			</view>
			
		</view>
	</view>
</template>

<script>
import {activityList,post} from '@/utils/interface.js'
export default {
	data() {
		return {
			index: 0,
			info:{},
			sendValueState:false,
			comment:"",
			activityId:"",
			commentList:[],
			u_id:"",
			userInfo:{},
			reward:[],
			type:""
		};
	},
	methods: {
		tap(keys) {
			this.index = keys;
		},
		getComment(){
			activityList({method:"activities.comment",upload_id:this.info.id}).then(res=>{
				console.log(res.data)
				this.commentList = res.data
			})
		},
		userClick(){
			post({method:"activities.upload_browse",upload_id:this.info.id,token:uni.getStorageSync('userToken')}).then(res=>{
				console.log(res.data)
			})
		},
		tickets(id){
			post({method:"activities.ticket",upload_id:this.info.id,token:uni.getStorageSync('userToken')}).then(res=>{
				console.log(res.data);
				if(res.status == false){
					uni.showToast({
						title:res.msg,
						icon:"none"
						
					})
					return false
				}
				uni.showToast({
					title:"投票成功"
				})
				this.info.ticket++
				
			})
		},
		send(){
			console.log(this.comment)
			if(this.comment){
				post({method:"activities.post_comment",upload_id:this.info.id,content:this.comment,token:uni.getStorageSync('userToken')}).then(res=>{
					console.log(res)
					
					if(res.status){
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
						this.comment = ""
						this.sendValueState = false
						this.getComment()
					}else{
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
					}
				})
			}
		},
		getUser(){
			activityList({method:"activities.my_submit",activity_id:this.activityId,token:uni.getStorageSync('userToken')}).then(res=>{
				console.log(res.data)
				this.userInfo = res.data.my
			})
		},
		getReward(){
			activityList({method:"activities.task_ticket_user",token:uni.getStorageSync('userToken'),upload_id:this.info.id}).then(res=>{
				console.log(res,'list')
				res.data.map(item=>{
					item.time = item.create_time.split(" ")[0]
				})
				console.log(res.data)
				this.reward = res.data
			})
		}
	},
	onLoad(options){
		this.info = JSON.parse(options.info)
		console.log(this.info)
		this.getComment()
		this.userClick()
		this.activityId = options.id
		this.getUser()
		this.getReward()
		this.type = options.type
	}
};
</script>

<style>
	.imgList{
		width: 100%;
	}
	.imgList image{
		width: 100%;
	}
	.null{
		display: flex;
		justify-content: center;
		align-items: center;
		color: #999;
		font-size: 30upx;
		height: 400upx;
	}
	.video{
		width: 100%;
	}
	.sendComment{
		display: flex;
		align-items: center;
		background: #e7e7e7;
		/* margin: 0 30upx; */
		border-radius: 15upx;
		justify-content: space-between;
		padding:20upx 30upx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}
	
	.sendComment .sendBtn{
		font-size: 30upx;
		color: #a9a9a9;
		border: 1upx solid #a9a9a9;
		border-radius: 15upx;
		display: block;
		width: 120upx;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
	}
	.sendComment .act{
		background: #007AFF;
		color: #fff;
		border: none;
	}
	.sendComment input{
		background: #fff;
		height: 60upx;
		text-indent: 30upx;
		border-radius: 8upx;
		flex: 2;
		margin-right: 20upx;
	}
.container {
	padding-top: 88upx;
}
.header-image {
}
.header-image image {
	width: 100%;
	height: 422upx;
	background: #f3f3f3;
}
.tab-box {
	display: flex;
	align-items: center;
	height: 100upx;
	padding: 0 20upx;
}
.tab-box view {
	text-align: center;
	flex: 1;
	font-size: 24upx;
	height: 60upx;
}
.tab-box .after {
	color: #f8a62a;
	position: relative;
}
.tab-box .after::after {
	position: absolute;
	bottom: 0;
	left: 140upx;
	right: 140upx;
	height: 1px;
	content: '';
	background: #f8a62a;
}
.author-commonts {
	padding: 0 20upx;
	display: flex;
	align-items: flex-start;
	margin-top: 30rpx;
}
.author-img {
	width: 74upx;
	height: 74upx;
	border-radius: 100%;
	background: #ddd;
	margin-right: 20upx;
}
.author-name {
	color: #303030;
	font-size: 28upx;
}
.author-details {
	background: #f4f8fb;
	font-size: 24upx;
	padding: 20upx 10upx;
	color: #999999;
	line-height: 30upx;
	margin-top: 10upx;
	border-radius: 12upx;
}
.author-flex {
	display: flex;
	align-items: center;
	font-size: 24upx;
	color: #999999;
	height: 60upx;
}
.author-flex view {
	margin-left: 20upx;
	display: flex;
	align-items: center;
}
.author-flex image {
	width: 40upx;
	height: 40upx;
	
	font-size: 24upx;
	margin-right: 10upx;
}

.flex-ens {
	display: flex;
	justify-content: flex-end;
}
.author-content {
	flex: 1;
}
.navor-list-image {
	display: flex;
	align-items: center;
}
.navor-list-image image {
	width: 64upx;
	height: 64upx;
	background: #f3f3f3;
	border-radius: 100%;
	overflow: hidden;
	margin-right: 20upx;
}
.navor-list-content {
	flex: 1;
}
.navor-list-content view {
	line-height: 60upx;
}
.navor-list-content view:nth-of-type(1) {
	font-size: 28upx;
}
.navor-list-content view:nth-of-type(2) {
	font-size: 24upx;
	color: #999999;
}
.comont-list {
	padding: 24upx 18upx;
	border-bottom: 1px solid #f3f3f3;
}
.navor-content {
	color: #1c1c22;
	font-size: 28upx;
	line-height: 60upx;
	text-indent: 2em;
}
.img-flex {
	display: flex;
	align-items: center;
	justify-content: flex-end;
}
.img-flex view {
	font-size: 26upx;
	margin-right: 15upx;
}
.img-flex image {
	width: 34upx;
	height: 34upx;
	margin-right: 20upx;
}
.img-flex view {
	display: flex;
	align-items: center;
}
.comont-records {
	display: flex;
	align-items: center;
	padding: 24upx 18upx;
	border-bottom: 1px solid #f3f3f3;
}
.comont-records image {
	width: 64upx;
	height: 64upx;
	background: #f3f3f3;
	border-radius: 100%;
	overflow: hidden;
	margin-right: 20upx;
}
.navor-records-content {
	display: flex;
	align-items: center;
}
.navor-records-content {
	background: #f4f8fb;
	flex: 1;
	padding-left: 20upx;
}
.records-name {
	font-size: 28upx;
	line-height: 60upx;
}
.records-date {
	font-size: 12px;
	color: #999999;
	line-height: 60upx;
}
.floews {
	color: #333;
	font-size: 32upx;
	margin-left: 40upx;
	width: 320upx;
	display: block;
	margin-left: 30upx;
}
.addnumber {
	color: #333;
	font-size: 32upx;
	margin-left: 40upx;
}
</style>
